package com.itheima.d8_thread_pool;

import java.util.concurrent.*;

/*
     目标：线程池处理任务
     需求 : 使用线程池处理Callable类型任务
 */
public class ThreadPoolTest3 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(3,
                10,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(20),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        Future<Integer> submit = executor.submit(new cul(10));
        Future<Integer> submit1 = executor.submit(new cul(20));
        Future<Integer> submit2 = executor.submit(new cul(30));
        try {
            System.out.println(submit.get());
            System.out.println(submit1.get());
            System.out.println(submit2.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
class cul implements Callable<Integer>{
private int num;
    public cul(int num) {
        this.num = num;
    }
    int sum;
    @Override
    public Integer call() throws Exception {
        for (int i = 0; i < num; i++){
            sum += i;
        }
        return sum;



    }
}
